﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using becom.Model;
namespace becom.BLL
{
	/// <summary>
	/// oa_reward
	/// </summary>
	public partial class oa_reward
	{
		private readonly becom.DAL.oa_reward dal=new becom.DAL.oa_reward();
		public oa_reward()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int reward_id)
		{
			return dal.Exists(reward_id);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add(becom.Model.oa_reward model)
		{
			dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(becom.Model.oa_reward model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int reward_id)
		{
			
			return dal.Delete(reward_id);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string reward_idlist )
		{
			return dal.DeleteList(reward_idlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public becom.Model.oa_reward GetModel(int reward_id)
		{
			
			return dal.GetModel(reward_id);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public becom.Model.oa_reward GetModelByCache(int reward_id)
		{
			
			string CacheKey = "oa_rewardModel-" + reward_id;
			object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(reward_id);
					if (objModel != null)
					{
						int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (becom.Model.oa_reward)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<becom.Model.oa_reward> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<becom.Model.oa_reward> DataTableToList(DataTable dt)
		{
			List<becom.Model.oa_reward> modelList = new List<becom.Model.oa_reward>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				becom.Model.oa_reward model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new becom.Model.oa_reward();
					if(dt.Rows[n]["reward_id"]!=null && dt.Rows[n]["reward_id"].ToString()!="")
					{
						model.reward_id=int.Parse(dt.Rows[n]["reward_id"].ToString());
					}
					if(dt.Rows[n]["person_id"]!=null && dt.Rows[n]["person_id"].ToString()!="")
					{
						model.person_id=int.Parse(dt.Rows[n]["person_id"].ToString());
					}
					if(dt.Rows[n]["reward_date"]!=null && dt.Rows[n]["reward_date"].ToString()!="")
					{
						model.reward_date=DateTime.Parse(dt.Rows[n]["reward_date"].ToString());
					}
					if(dt.Rows[n]["reward_sort"]!=null && dt.Rows[n]["reward_sort"].ToString()!="")
					{
						model.reward_sort=int.Parse(dt.Rows[n]["reward_sort"].ToString());
					}
					if(dt.Rows[n]["honor_name"]!=null && dt.Rows[n]["honor_name"].ToString()!="")
					{
					model.honor_name=dt.Rows[n]["honor_name"].ToString();
					}
					if(dt.Rows[n]["reward_type"]!=null && dt.Rows[n]["reward_type"].ToString()!="")
					{
						model.reward_type=int.Parse(dt.Rows[n]["reward_type"].ToString());
					}
					if(dt.Rows[n]["reward_content"]!=null && dt.Rows[n]["reward_content"].ToString()!="")
					{
					model.reward_content=dt.Rows[n]["reward_content"].ToString();
					}
					if(dt.Rows[n]["grant_unit"]!=null && dt.Rows[n]["grant_unit"].ToString()!="")
					{
					model.grant_unit=dt.Rows[n]["grant_unit"].ToString();
					}
					if(dt.Rows[n]["attach_path"]!=null && dt.Rows[n]["attach_path"].ToString()!="")
					{
					model.attach_path=dt.Rows[n]["attach_path"].ToString();
					}
					if(dt.Rows[n]["attach_filename"]!=null && dt.Rows[n]["attach_filename"].ToString()!="")
					{
					model.attach_filename=dt.Rows[n]["attach_filename"].ToString();
					}
					if(dt.Rows[n]["note"]!=null && dt.Rows[n]["note"].ToString()!="")
					{
					model.note=dt.Rows[n]["note"].ToString();
					}
					if(dt.Rows[n]["reward_grade"]!=null && dt.Rows[n]["reward_grade"].ToString()!="")
					{
					model.reward_grade=dt.Rows[n]["reward_grade"].ToString();
					}
					if(dt.Rows[n]["reward_other_name"]!=null && dt.Rows[n]["reward_other_name"].ToString()!="")
					{
					model.reward_other_name=dt.Rows[n]["reward_other_name"].ToString();
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
	}
}

